 // pages/news/news.js
 Page({
  data: {
    news: [],
    websites: [],
    notice: '',
    bannerImages: [
      { url: "https://z1.ax1x.com/2023/11/25/pi0unxI.jpg" },
      { url: "https://z1.ax1x.com/2023/11/25/pi0uKMt.jpg" },
      { url: "https://z1.ax1x.com/2023/11/25/pi0uMsP.jpg" },
    ],
  },
  onLoad: function () {
    var that = this;
    wx.request({
      url: 'http://localhost:3000/api/data/news',
      success: function (res) {
        console.log('收到数据：', res.data);
        let data = res.data.map(item => ({id: item.id, title: item.title, news: item.news}));
        that.setData({
          news: data
        });
      }
    });
    wx.request({
      url: 'http://localhost:3000/api/data/notice',
      success: function (res) {
        console.log('收到通知：', res.data);
        that.setData({
          notice: res.data[0].notice  // 获取数组中的第一个元素
        });
      }
    });
  },
  goToDetail: function(e) {
    let id = e.currentTarget.dataset.id;
    console.log('传递的id是：', id);  // 打印 id
    wx.navigateTo({
      url: '/pages/news/detail/detail?id=' + id
    });
  }
});